package org.servlet;

import org.service.CheckUsernameService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UsernameIsExistServlet extends HttpServlet {

    private CheckUsernameService service;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user = req.getParameter("username");
        service = new CheckUsernameService();
        boolean result = service.usernameIsExist(user);
        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        if(result){
            out.print("Exist");
        }else{
            out.print("Not Exist");
        }
        out.flush();
        out.close();
    }
}
